/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.sql.*;
import java.util.Vector;
import javax.swing.text.StyledEditorKit.BoldAction;

/**
 *
 * @author RUOL
 */
public class Khoa {
    private String Makhoa;
    private String Tenkhoa;
    private float  Phidong;

    public Khoa() {
    }

    public Khoa(String Makhoa, String Tenkhoa, float Phidong) {
        this.Makhoa = Makhoa;
        this.Tenkhoa = Tenkhoa;
        this.Phidong = Phidong;
    }

    /**
     * Giá trị trả về là một chuổi
     */
    public String getMakhoa() {
        return Makhoa;
    }

    /**
     * @param Makhoa the Makhoa to set
     */
    public void setMakhoa(String Makhoa) {
        this.Makhoa = Makhoa;
    }

    /**
     * Giá trị trả về là một chuổi
     */
    public String getTenkhoa() {
        return Tenkhoa;
    }

    /**
     * @param Tenkhoa the Tenkhoa to set
     */
    public void setTenkhoa(String Tenkhoa) {
        this.Tenkhoa = Tenkhoa;
    }

    /**
     * Giá trị trả về là một số kiểu float
     */
    public float getPhidong() {
        return Phidong;
    }

    /**
     * @param Phidong the Phidong to set
     */
    public void setPhidong(float Phidong) {
        this.Phidong = Phidong;
    }
    
    public Vector<Vector> DanhSachKhoa()
    {
        Vector<Vector> dsdm = new Vector<Vector>();
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from Khoa";
            Statement st=con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                Vector<Object> dm = new Vector<Object>();
                dm.add(rs.getString("Makhoa"));
                dm.add(rs.getString("Tenkhoa"));
                dm.add(rs.getFloat("Phidong"));
                dsdm.add(dm);
            }
        }
        catch(Exception ex)
        {
            dsdm = null;
        }
        
        return dsdm;
    }
    //------------
    public Khoa ThongTinKhoa()
    {
        Khoa dm = new Khoa();
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from Khoa where Makhoa = '"+this.Makhoa+"'";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                dm.setMakhoa(rs.getString("Makhoa"));
                dm.setTenkhoa(rs.getString("Tenkhoa"));
                dm.setPhidong(rs.getFloat("Phidong"));
            }
        }
        catch(Exception ex)
        {
            dm = null;
        }
        
        return dm;
    }
    public boolean CapNhatKhoa()
    {
        boolean kq = true;
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "update Khoa set Makhoa='"+this.Makhoa+"', Tenkhoa='"+this.Tenkhoa+"' where Makhoa='"+this.Makhoa+"'";
            Statement st = con.createStatement();
            kq = st.executeUpdate(query) > 0;
        }
        catch(Exception ex)
        {
            kq = false;
        }
        
        return kq;
    }
     public boolean XoaKhoa()
    {
        boolean kq = true;
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "delete from Khoa where Makhoa='"+this.Makhoa+"'";
            Statement st = con.createStatement();
            kq = st.executeUpdate(query) > 0;
        }
        catch(Exception ex)
        {
            kq = false;
        }
        
        return kq;
    }
}
